﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OOPA_opdracht.Model
{
    public class NodeAND : MainNode
    {
        //only 1 and 1 returns 1
        public static Inputs doubleOperatorNode(Inputs firstInput, Inputs secondInput)
        {
            if (firstInput == Inputs.NO_INPUT) return Inputs.NO_INPUT;
            if (secondInput == Inputs.NO_INPUT) return Inputs.NO_INPUT;
            return firstInput == Inputs.INPUT_HIGH && secondInput == Inputs.INPUT_HIGH ? Inputs.INPUT_HIGH : Inputs.INPUT_LOW;
        }

        public override String getKey()
        {
            return "AND";
        }

        public override object Clone()
        {
            return new NodeAND();
        }

        public override void show()
        {
            Console.WriteLine(getKey() + ": \t" + nodeName);
            Console.WriteLine("First input: \t" + firstInput);
            Console.WriteLine("Second input: \t" + secondInput);
            Console.WriteLine("Output: \t" + output);
            Console.WriteLine();
        }

        public override void setInput(Inputs input)
        {
            if (firstInput == Inputs.NO_INPUT)
                firstInput = input;
            else if (secondInput == Inputs.NO_INPUT)
            {
                secondInput = input;
                count();
            }
        }

        public override void setOutput() { }

        private void count()
        {
            output = doubleOperatorNode(firstInput, secondInput);
            if (output != Inputs.NO_INPUT)
                foreach (MainNode n in nextNodes)
                    n.setInput(output);
        }
    }
}
